package com.jingyanzi.sys.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jingyanzi.sys.dao.SysOperateLogsMapper;
import com.jingyanzi.sys.domain.OperateLogsDO;
import com.jingyanzi.sys.domain.query.OperateLogsQueryDO;
import com.jingyanzi.sys.domain.result.ResultDO;
import com.jingyanzi.sys.domain.result.ResultSupport;
import com.jingyanzi.sys.domain.service.IOperateLogsService;
import com.jingyanzi.sys.entity.SysOperateLogs;
import com.jingyanzi.sys.entity.SysOperateLogsExample;
import com.jingyanzi.sys.entity.SysOperateLogsExample.Criteria;
import com.jingyanzi.sys.util.BeanUtilsExtends;

@Service("iOperateLogsService")
public class OperateLogsServiceImpl extends BaseServiceImpl implements IOperateLogsService {

	@Autowired
	private SysOperateLogsMapper operateLogsMapper;

	@Override
	public ResultDO add(OperateLogsDO operateLogsDO) {
		
		SysOperateLogs operateLogs = new SysOperateLogs();
		
		ResultSupport result = BeanUtilsExtends.copy(operateLogs, operateLogsDO);
		
		if (!result.isSuccess()) {
			return result;
		}

		operateLogs.setCreatetime(Calendar.getInstance().getTime());
		
		operateLogs.setId(UUID.randomUUID().toString().replace("-", ""));
		
		int r = -1;
		
		r = operateLogsMapper.insert(operateLogs);
		if (r < 1) {
			result.setSuccess(false);
			return result;
		}

		result.setModel(ResultDO.FIRST_MODEL_KEY, operateLogs.getId());
		return result;
	}

	@Override
	public ResultDO querry(OperateLogsQueryDO query) {

		List<SysOperateLogs> logsList = new ArrayList<SysOperateLogs>();
		ResultSupport result = new ResultSupport();
		SysOperateLogsExample example = new SysOperateLogsExample();
		Criteria createCriteria = example.createCriteria();
		

		try {
			logsList = operateLogsMapper.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
		}

		List<OperateLogsDO> logsDOList = null;

		logsDOList = getOperateLogsDOList(logsList);// OperateLogsDO继承BaseDO后就不能拷贝，因为id的类型不一样

		result.setModel(ResultSupport.FIRST_MODEL_KEY, logsDOList);

		return result;
	}

}
